#!/usr/bin/python2
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""A small utility to extract locale information from region database."""

from __future__ import print_function

import json
import sys


# The region database install by virtual/chromeos-regions.
CROS_REGION_DATABASE = '/usr/share/misc/cros-regions.json'


def main():
  db_path = sys.argv[1] if len(sys.argv) > 1 else CROS_REGION_DATABASE

  with open(db_path) as f:
    db = json.load(f)

  # In recovery image we can't afford to put JSON programs so we want to provide
  # a simple database.
  for key, value in db.iteritems():
    print('%s\t%s' % (key, value['locales'][0]))


if __name__ == '__main__':
  main()
